#ifndef _ENGINE_H
#define _ENGINE_H

#include "Common.h"
#include "Scene.h"

namespace Pandora
{

	class CEngine
	{
		CScene scene;
		CColor** screenBuffer;

		void InitializeScreenBuffer();
	public:
		CEngine() : scene(CScene()) 
		{	
			screenBuffer = NULL;
		}

		CEngine(CScene s) : scene(s) 
		{	
			InitializeScreenBuffer();
		}

		~CEngine()
		{
			if(screenBuffer)
			{
				for(int i = 0; i < scene.GetHeight(); i++)
					delete [] screenBuffer[i];

				delete [] screenBuffer;
			}
		}

		void RenderFrame();
		void SaveToFile(char* filename);

		CScene& GetScene() { return scene; }
		CColor** GetBuffer() { return screenBuffer; }

		void SetScene(CScene& s) { scene = s; InitializeScreenBuffer(); }
		void SetScene(CScene* s) { scene = *s; InitializeScreenBuffer(); }

		CColor TraceRay(CRay viewRay, float coef, int level);

		float srgbEncode(float c);
	};

}; //namespace Pandora

#endif /* _ENGINE_h */